package com.njlime.sys.controller;

import com.njlime.core.base.controller.BaseController;
import com.njlime.core.exception.ExceptionState;
import com.njlime.core.helper.GlobalValue;
import com.njlime.core.helper.PageBean;
import com.njlime.core.web.validation.annotation.support.ValidateService;
import com.njlime.sys.entities.Menu;
import com.njlime.sys.entities.UnitWxConfig;
import com.njlime.sys.security.util.UserUtils;
import com.njlime.sys.service.MenuService;
import com.njlime.sys.service.UserConfigService;
import com.njlime.sys.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Dean on 2017-7-25.
 */
@Controller
@RequestMapping(value = "sys/userConfig")
public class UserConfigController extends BaseController {
    @Resource
    private UserConfigService userConfigService;
    @Resource
    private UserService userService;


    //-------------------控制器--------------------

    /**
     * 跳转权限管理页面
     * @return
     */
    @RequestMapping(value = "toUserconfig")
    public ModelAndView menuManage(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/sys/terrace/config/index");
        return modelAndView;
    }

    /**
     * 跳转我的账户页面
     * @return
     */
    @RequestMapping(value = "myAccountView")
    public ModelAndView myAccountView(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/sys/terrace/config/myAccount");
        modelAndView.addObject("user",userService.getById(getLoginUser().getId()));
        return modelAndView;
    }

    //------------------接口-----------------

    /**
     * 获取菜单列表分页
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public String list(HttpServletRequest request) {
        try {
            int unitId = UserUtils.getUser().getRootUnit().getId();
            return toJsonListData(userConfigService.list(unitId));
        } catch (Exception e) {
            return toJsonErrorData(ExceptionState.PARAM_EXCEPTION, e.getMessage());
        }
    }


}
